package com.hyz.login.controller;



import com.hyz.login.service.LoginService;
import com.hyz.login.service.PaiBanService;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.net.URLCodec;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.jws.soap.SOAPBinding;
import java.io.UnsupportedEncodingException;


@Controller
public class LoginController {

    private Logger logger = LoggerFactory.getLogger(LoginController.class);
    @Autowired
    private LoginService loginService;
    @Autowired
    private PaiBanService paiBanService;

    @RequestMapping("/toLogin")
    public String tologin(){
        return "/demo/login";
    }

    @RequestMapping("/")
    public String login(){
        return "/demo/login";
    }

    @RequestMapping("/page/main")
    public String main(Model model){
        model.addAttribute("paiBan",paiBanService.PaiBan());
        System.out.println(paiBanService.PaiBan());
        return "/page/main";
    }

    @RequestMapping("/page/toIndex")
    public String index(String loginName, String pwd, Model model){
        System.out.println(pwd);
        String passwordMD5 = DigestUtils.md5Hex(pwd);
        logger.info(passwordMD5+"----------------------");
        logger.info(loginName+"----------------------");
        model.addAttribute("user",loginService.userFind(loginName,passwordMD5));
        return "/page/index";
    }


}
